package com.gdth.widget.edittext;

import com.gdth.R;
import com.gdth.widget.edittext.listener.TextWatcherListener;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BaseEditText extends LinearLayout{
	protected Context context;
	
	/**
	 * 标题
	 */
	protected TextView txt_label;
	
	/**
	 * 输入框
	 */
	protected EditText txt_value;
	
	private int layout;
	
	public BaseEditText(Context context) {
		super(context);
		
		this.context = context;
		this.layout = R.layout.widget_textview_image;
		
		init();
		initView();
	}
	
	public BaseEditText(Context context, int layout) {
		super(context);
		
		this.context = context;
		this.layout = layout;
		
		init();
		initView();
	}
	
	public BaseEditText(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		this.context = context;
		this.layout = R.layout.widget_textview_image;
		
		init();
		initView();
	}
	
	public BaseEditText(Context context, AttributeSet attrs, int layout) {
		super(context, attrs);
		
		this.context = context;
		this.layout = layout;
		
		init();
		initView();
	}
	
	private void init() {
		LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(layout, this);
	}
	
	protected void initView(){
        txt_label = (TextView) findViewById(R.id.widget_edittext_label);
        txt_value = (EditText) findViewById(R.id.widget_edittext_value);
	}
	
	public void setLabel(String label){
		txt_label.setText(label);
	}
	
	public void setLabel(int label){
		txt_label.setText(context.getResources().getString(label));
	}
	
	public void setHint(String label){
		txt_value.setHint(label);
	}
	
	public void setHint(int label){
		txt_value.setHint(context.getResources().getString(label));
	}
	
	public String getValue(){
		return txt_value.getText().toString();
	}
	
	public void setValue(String value){
		txt_value.setText(value);
	}
	
	public void setInputType(int inputType){
//		int inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL;
		txt_value.setInputType(inputType);
	}
	
	public void addTextChangedListener(int length) {
		txt_value.addTextChangedListener(new TextWatcherListener(context, txt_value, length));
	}
}
